﻿using Dapper;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using OMG.Fill.Frunit.Model;
using OMG.Fill.Frunit.Model.Ent;
using OMG.Fill.Frunit.Service;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace OMG.Fill.Frunit.Services
{
    /// <summary>
    /// 表5蔬菜生产经验实体表T_FruProsecution通用操作类
    /// </summary>
    public class FruProsecutionServices : FruProsecutions
    {
        public Pager<List<FruProsecutionEntity>> GetPageList(FruProsecutionQuery query)
        {
            Pager<List<FruProsecutionEntity>> obj = new Pager<List<FruProsecutionEntity>>();
            var paramlist = new DynamicParameters();
            string strWhereSql = "";//from 表在下面，需完善其他查询条件在这里接的写，格式为："and xxx=@xxx空格,如下注释部分代码所示："
            //if (!string.IsNullOrEmpty(query.GroupCode))
            //{
            //  strWhereSql += "and GroupCode = @GroupCode ";
            //  paramlist.Add("GroupCode", query.GroupCode);
            //}
            string strFromSql = "from dbo.T_FruProsecution where 1=1 " + strWhereSql;
            string strTotal = "select count(1)" + strFromSql + strWhereSql;
            string strOrderSql = "";//自定义完成order by语句
            string strSql = @"select * from (select *,ROW_NUMBER() over (order by Id ) as RowNumber " + strFromSql + ") as t ";
            strSql += "where t.RowNumber between  @minRow and @maxRow" + strOrderSql;
            paramlist.Add("minRow", query.MinRow);
            paramlist.Add("maxRow", query.MaxRow);
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.rows = dbCon.Query<FruProsecutionEntity>(strSql, paramlist).ToList();
                    obj.total = dbCon.Query<int>(strTotal, paramlist).FirstOrDefault();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("获取表5蔬菜生产经验实体表T_FruProsecution分页列表失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 判定是否生成过报表
        /// </summary>
        /// <param name="reportId"></param>
        /// <returns>没生成过true,否则false</returns>
        public bool CheckRepCount(string reportId)
        {
            string strSql = @"select count(1) from dbo.T_FruProsecution where ReportId=@ReportId";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    //为0，没生成过true,否则false
                    return dbCon.Query<int>(strSql, new { ReportId = reportId }).FirstOrDefault() == 0 ? true : false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("更新表3生产情况调查表T_FruProsecution对象信息失败", ex);
                return false;
            }
        }
        /// <summary>
        /// 读取导入的Excel数据
        /// </summary>
        /// <param name="pathName">导入文件路径</param>
        /// <param name="fileSuffix">文件后缀</param>
        /// <param name="sheetName">sheet名称</param>
        /// <param name="startRow">从第几行开始读取数据</param>
        /// <returns></returns>
        public List<FruProsecutionModel> ExcelToModel(string pathName, string fileSuffix, string sheetName, int startRow)
        {

            IWorkbook workbook = null;
            ISheet sheet = null;
            List<FruProsecutionModel> list = new List<FruProsecutionModel>();
            FileStream fs = new FileStream(pathName, FileMode.Open, FileAccess.Read);
            switch (fileSuffix)
            {
                case ".xls":
                    workbook = new HSSFWorkbook(fs);
                    break;
                case ".xlsx":
                    workbook = new XSSFWorkbook(fs);
                    break;
                default:
                    workbook = new HSSFWorkbook(fs);
                    break;
            }
            if (!string.IsNullOrEmpty(sheetName))
            {
                sheet = workbook.GetSheet(sheetName);
                if (sheet == null) //如果没有找到指定的sheetName对应的sheet，则尝试获取第一个sheet
                {
                    sheet = workbook.GetSheetAt(0);
                }
            }
            else
            {
                sheet = workbook.GetSheetAt(0);
            }
            if (sheet != null)
            {
                IRow firstRow = sheet.GetRow(4);//从第五行开始读
                int cellCount = firstRow.LastCellNum;//获取列数

                //获取有数据的行数
                int rowCount = 0;
                for (int i = startRow; i <= sheet.LastRowNum; i++)
                {
                    IRow row = sheet.GetRow(i);
                    if (row != null)
                    {
                        rowCount = sheet.GetRow(i).RowNum;
                    }
                    else
                    {
                        break;
                    }
                }
                for (int i = startRow; i <= rowCount; i++)
                {
                    IRow row = sheet.GetRow(i);
                    FruProsecutionModel model = new FruProsecutionModel();
                    model.year = row.GetCell(0).ToString();
                    if (row.GetCell(1) != null && row.GetCell(1).ToString() != "")
                    {
                        model.MarketNum = int.Parse(row.GetCell(1).ToString());
                    }
                    //else
                    //{
                    //    model.MarketNum = null;
                    //}
                    if (row.GetCell(2) != null && row.GetCell(2).ToString() != "")
                    {
                        model.CdxMarket = int.Parse(row.GetCell(2).ToString());
                    }
                    //else
                    //{
                    //    model.CdxMarket = null;
                    //}
                    if (row.GetCell(3) != null && row.GetCell(3).ToString() != "")
                    {
                        model.ZypfMarket = int.Parse(row.GetCell(3).ToString());
                    }
                    //else
                    //{
                    //    model.ZypfMarket = null;
                    //}
                    if (row.GetCell(4) != null && row.GetCell(4).ToString() != "")
                    {
                        model.QyxzhpfMarket = int.Parse(row.GetCell(4).ToString());
                    }
                    //else
                    //{
                    //    model.QyxzhpfMarket = null;
                    //}
                    if (row.GetCell(5) != null && row.GetCell(5).ToString() != "")
                    {
                        model.FruCompanyNum = int.Parse(row.GetCell(5).ToString());
                    }
                    //else
                    //{
                    //    model.FruCompanyNum = null;
                    //}
                    if (row.GetCell(6) != null && row.GetCell(6).ToString() != "")
                    {
                        model.ZzNum_country = int.Parse(row.GetCell(6).ToString());
                    }
                    //else
                    //{
                    //    model.ZzNum_country = null;
                    //}
                    if (row.GetCell(7) != null && row.GetCell(7).ToString() != "")
                    {
                        model.ZzNum_pro = int.Parse(row.GetCell(7).ToString());
                    }
                    //else
                    //{
                    //    model.ZzNum_pro = null;
                    //}
                    if (row.GetCell(8) != null && row.GetCell(8).ToString() != "")
                    {
                        model.ZzNum_city = int.Parse(row.GetCell(8).ToString());
                    }
                    //else
                    //{
                    //    model.ZzNum_city = null;
                    //}
                    if (row.GetCell(9) != null && row.GetCell(9).ToString() != "")
                    {
                        model.ZzNum_county = int.Parse(row.GetCell(9).ToString());
                    }
                    //else
                    //{
                    //    model.ZzNum_county = null;
                    //}
                    if (row.GetCell(10) != null && row.GetCell(10).ToString() != "")
                    {
                        model.ZzNum_other = int.Parse(row.GetCell(10).ToString());
                    }
                    //else
                    //{
                    //    model.ZzNum_other = null;
                    //}
                    if (row.GetCell(11) != null && row.GetCell(11).ToString() != "")
                    {
                        model.HzNum = int.Parse(row.GetCell(11).ToString());
                    }
                    //else
                    //{
                    //    model.HzNum = null;
                    //}
                    if (row.GetCell(12) != null && row.GetCell(12).ToString() != "")
                    {
                        model.NhhzNum = int.Parse(row.GetCell(12).ToString());
                    }
                    //else
                    //{
                    //    model.NhhzNum = null;
                    //}
                    if (row.GetCell(13) != null && row.GetCell(13).ToString() != "")
                    {
                        model.NmzyhzNum = decimal.Parse(row.GetCell(13).ToString());
                    }
                    else
                    {
                        model.NmzyhzNum = null;
                    }
                    if (row.GetCell(14) != null && row.GetCell(14).ToString() != "")
                    {
                        model.NmhzYincome = decimal.Parse(row.GetCell(14).ToString());
                    }
                    else
                    {
                        model.NmhzYincome = null;
                    }
                    if (row.GetCell(15) != null && row.GetCell(15).ToString() != "")
                    {
                        model.JtncNum = int.Parse(row.GetCell(15).ToString());
                    }
                    //else
                    //{
                    //    model.JtncNum = null;
                    //}
                    if (row.GetCell(16) != null && row.GetCell(16).ToString() != "")
                    {
                        model.JtncnhNum = int.Parse(row.GetCell(16).ToString());
                    }
                    //else
                    //{
                    //    model.JtncnhNum = null;
                    //}
                    if (row.GetCell(17) != null && row.GetCell(17).ToString() != "")
                    {
                        model.JtncjyArea = decimal.Parse(row.GetCell(17).ToString());
                    }
                    else
                    {
                        model.JtncjyArea = null;
                    }
                    if (row.GetCell(18) != null && row.GetCell(18).ToString() != "")
                    {
                        model.JtncYincome = decimal.Parse(row.GetCell(18).ToString());
                    }
                    else
                    {
                        model.JtncYincome = null;
                    }
                    if (row.GetCell(19) != null && row.GetCell(19).ToString() != "")
                    {
                        model.ZlrzNum_sfx = int.Parse(row.GetCell(19).ToString());
                    }
                    //else
                    //{
                    //    model.ZlrzNum_sfx = null;
                    //}
                    if (row.GetCell(20) != null && row.GetCell(20).ToString() != "")
                    {
                        model.ZlrzNum_sfq = int.Parse(row.GetCell(20).ToString());
                    }
                    //else
                    //{
                    //    model.ZlrzNum_sfq = null;
                    //}
                    if (row.GetCell(21) != null && row.GetCell(21).ToString() != "")
                    {
                        model.ZgcmsbNum = int.Parse(row.GetCell(21).ToString());
                    }
                    //else
                    //{
                    //    model.ZgcmsbNum = null;
                    //}
                    if (row.GetCell(22) != null && row.GetCell(22).ToString() != "")
                    {
                        model.ZgmpcpNum = int.Parse(row.GetCell(22).ToString());
                    }
                    //else
                    //{
                    //    model.ZgmpcpNum = null;
                    //}
                    if (row.GetCell(23) != null && row.GetCell(23).ToString() != "")
                    {
                        model.YnszmsbNum = int.Parse(row.GetCell(23).ToString());
                    }
                    //else
                    //{
                    //    model.YnszmsbNum = null;
                    //}
                    if (row.GetCell(24) != null && row.GetCell(24).ToString() != "")
                    {
                        model.ZlrzNum_wghNum = int.Parse(row.GetCell(24).ToString());
                    }
                    //else
                    //{
                    //    model.ZlrzNum_wghNum = null;
                    //}
                    if (row.GetCell(25) != null && row.GetCell(25).ToString() != "")
                    {
                        model.ZlrzNum_wghmj = decimal.Parse(row.GetCell(25).ToString());
                    }
                    else
                    {
                        model.ZlrzNum_wghmj = null;
                    }
                    if (row.GetCell(26) != null && row.GetCell(26).ToString() != "")
                    {
                        model.ZlrzNum_bluecp = int.Parse(row.GetCell(26).ToString());
                    }
                    //else
                    //{
                    //    model.ZlrzNum_bluecp = null;
                    //}
                    if (row.GetCell(27) != null && row.GetCell(27).ToString() != "")
                    {
                        model.ZlrzNum_bluecpmj = decimal.Parse(row.GetCell(27).ToString());
                    }
                    else
                    {
                        model.ZlrzNum_bluecpmj = null;
                    }
                    if (row.GetCell(28) != null && row.GetCell(28).ToString() != "")
                    {
                        model.ZlrzNum_dlsb = int.Parse(row.GetCell(28).ToString());
                    }
                    //else
                    //{
                    //    model.ZlrzNum_dlsb = null;
                    //}
                    if (row.GetCell(29) != null && row.GetCell(29).ToString() != "")
                    {
                        model.ZlrzNum_dlbh = int.Parse(row.GetCell(29).ToString());
                    }
                    //else
                    //{
                    //    model.ZlrzNum_dlbh = null;
                    //}
                    //if (row.GetCell(1) != null && row.GetCell(1).ToString() != "")
                    //{
                    //    model.FruCompanyNum = decimal.Parse(row.GetCell(1).ToString());
                    //}
                    //else
                    //{
                    //    model.FruCompanyNum = null;
                    //}
                    //if (row.GetCell(2) != null && row.GetCell(2).ToString() != "")
                    //{
                    //    model.ZzNum_pro = decimal.Parse(row.GetCell(2).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_pro = null;
                    //}
                    //if (row.GetCell(3) != null && row.GetCell(3).ToString() != "")
                    //{
                    //    model.ZzNum_city = decimal.Parse(row.GetCell(3).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_city = null;
                    //}
                    //if (row.GetCell(4) != null && row.GetCell(4).ToString() != "")
                    //{
                    //    model.ZzNum_singel = decimal.Parse(row.GetCell(4).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_singel = null;
                    //}
                    //if (row.GetCell(5) != null && row.GetCell(5).ToString() != "")
                    //{
                    //    model.ZzNum_yye1 = decimal.Parse(row.GetCell(5).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_yye1 = null;
                    //}
                    //if (row.GetCell(6) != null && row.GetCell(6).ToString() != "")
                    //{
                    //    model.ZzNum_yye2 = decimal.Parse(row.GetCell(6).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_yye2 = null;
                    //}
                    //if (row.GetCell(7) != null && row.GetCell(7).ToString() != "")
                    //{
                    //    model.ZzNum_yye3 = decimal.Parse(row.GetCell(7).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_yye3 = null;
                    //}
                    //if (row.GetCell(8) != null && row.GetCell(8).ToString() != "")
                    //{
                    //    model.ZzNum_yye4 = decimal.Parse(row.GetCell(8).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_yye4 = null;
                    //}
                    //if (row.GetCell(9) != null && row.GetCell(9).ToString() != "")
                    //{
                    //    model.ZzNum_yye5 = decimal.Parse(row.GetCell(9).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_yye5 = null;
                    //}
                    //if (row.GetCell(10) != null && row.GetCell(10).ToString() != "")
                    //{
                    //    model.ZzNum_yye6 = decimal.Parse(row.GetCell(10).ToString());
                    //}
                    //else
                    //{
                    //    model.ZzNum_yye6 = null;
                    //}
                    //if (row.GetCell(11) != null && row.GetCell(11).ToString() != "")
                    //{
                    //    model.SgjgNum = decimal.Parse(row.GetCell(11).ToString());
                    //}
                    //else
                    //{
                    //    model.SgjgNum = null;
                    //}
                    //if (row.GetCell(12) != null && row.GetCell(12).ToString() != "")
                    //{
                    //    model.SgyxNum = decimal.Parse(row.GetCell(12).ToString());
                    //}
                    //else
                    //{
                    //    model.SgyxNum = null;
                    //}
                    //if (row.GetCell(13) != null && row.GetCell(13).ToString() != "")
                    //{
                    //    model.SgwmNum = decimal.Parse(row.GetCell(13).ToString());
                    //}
                    //else
                    //{
                    //    model.SgwmNum = null;
                    //}
                    //if (row.GetCell(14) != null && row.GetCell(14).ToString() != "")
                    //{
                    //    model.DzswNum = decimal.Parse(row.GetCell(14).ToString());
                    //}
                    //else
                    //{
                    //    model.DzswNum = null;
                    //}
                    //if (row.GetCell(15) != null && row.GetCell(15).ToString() != "")
                    //{
                    //    model.HzNum = decimal.Parse(row.GetCell(15).ToString());
                    //}
                    //else
                    //{
                    //    model.HzNum = null;
                    //}
                    //if (row.GetCell(16) != null && row.GetCell(16).ToString() != "")
                    //{
                    //    model.ZyhzNum = decimal.Parse(row.GetCell(16).ToString());
                    //}
                    //else
                    //{
                    //    model.ZyhzNum = null;
                    //}
                    //if (row.GetCell(17) != null && row.GetCell(17).ToString() != "")
                    //{
                    //    model.NhhzNum = decimal.Parse(row.GetCell(17).ToString());
                    //}
                    //else
                    //{
                    //    model.NhhzNum = null;
                    //}
                    //if (row.GetCell(18) != null && row.GetCell(18).ToString() != "")
                    //{
                    //    model.NmzyhzNum = decimal.Parse(row.GetCell(18).ToString());
                    //}
                    //else
                    //{
                    //    model.NmzyhzNum = null;
                    //}
                    //if (row.GetCell(19) != null && row.GetCell(19).ToString() != "")
                    //{
                    //    model.SgzzNhNum = decimal.Parse(row.GetCell(19).ToString());
                    //}
                    //else
                    //{
                    //    model.SgzzNhNum = null;
                    //}
                    //if (row.GetCell(20) != null && row.GetCell(20).ToString() != "")
                    //{
                    //    model.ZZDHNum = decimal.Parse(row.GetCell(20).ToString());
                    //}
                    //else
                    //{
                    //    model.ZZDHNum = null;
                    //}
                    //if (row.GetCell(21) != null && row.GetCell(21).ToString() != "")
                    //{
                    //    model.ZZDHOne = decimal.Parse(row.GetCell(21).ToString());
                    //}
                    //else
                    //{
                    //    model.ZZDHOne = null;
                    //}
                    //if (row.GetCell(22) != null && row.GetCell(22).ToString() != "")
                    //{
                    //    model.ZZDHTwo = decimal.Parse(row.GetCell(22).ToString());
                    //}
                    //else
                    //{
                    //    model.ZZDHTwo = null;
                    //}
                    //if (row.GetCell(23) != null && row.GetCell(23).ToString() != "")
                    //{
                    //    model.ZZDHThree = decimal.Parse(row.GetCell(23).ToString());
                    //}
                    //else
                    //{
                    //    model.ZZDHThree = null;
                    //}
                    //if (row.GetCell(24) != null && row.GetCell(24).ToString() != "")
                    //{
                    //    model.YmjdNum = decimal.Parse(row.GetCell(24).ToString());
                    //}
                    //else
                    //{
                    //    model.YmjdNum = null;
                    //}
                    //if (row.GetCell(25) != null && row.GetCell(25).ToString() != "")
                    //{
                    //    model.YmNum = row.GetCell(25).ToString();
                    //}
                    //else
                    //{
                    //    model.YmNum = null;
                    //}
                    //if (row.GetCell(26) != null && row.GetCell(26).ToString() != "")
                    //{
                    //    model.ZlrzNum_sfx = decimal.Parse(row.GetCell(26).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_sfx = null;
                    //}
                    //if (row.GetCell(27) != null && row.GetCell(27).ToString() != "")
                    //{
                    //    model.ZlrzNum_sfq = decimal.Parse(row.GetCell(27).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_sfq = null;
                    //}
                    //if (row.GetCell(28) != null && row.GetCell(28).ToString() != "")
                    //{
                    //    model.ZlrzNum_sbs = decimal.Parse(row.GetCell(28).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_sbs = null;
                    //}
                    //if (row.GetCell(29) != null && row.GetCell(29).ToString() != "")
                    //{
                    //    model.ZlrzNum_bamj = decimal.Parse(row.GetCell(29).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_bamj = null;
                    //}
                    //if (row.GetCell(30) != null && row.GetCell(30).ToString() != "")
                    //{
                    //    model.ZlrzNum_rzmj = decimal.Parse(row.GetCell(30).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_rzmj = null;
                    //}
                    //if (row.GetCell(31) != null && row.GetCell(31).ToString() != "")
                    //{
                    //    model.ZlrzNum_rzsl = decimal.Parse(row.GetCell(31).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_rzsl = null;
                    //}
                    //if (row.GetCell(32) != null && row.GetCell(32).ToString() != "")
                    //{
                    //    model.ZlrzNum_wghNum = decimal.Parse(row.GetCell(32).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_wghNum = null;
                    //}
                    //if (row.GetCell(33) != null && row.GetCell(33).ToString() != "")
                    //{
                    //    model.ZlrzNum_wghmj = decimal.Parse(row.GetCell(33).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_wghmj = null;
                    //}
                    //if (row.GetCell(34) != null && row.GetCell(34).ToString() != "")
                    //{
                    //    model.ZlrzNum_bluecp = decimal.Parse(row.GetCell(34).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_bluecp = null;
                    //}
                    //if (row.GetCell(35) != null && row.GetCell(35).ToString() != "")
                    //{
                    //    model.ZlrzNum_bluecpmj = decimal.Parse(row.GetCell(35).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_bluecpmj = null;
                    //}
                    //if (row.GetCell(36) != null && row.GetCell(36).ToString() != "")
                    //{
                    //    model.ZlrzNum_dlsb = decimal.Parse(row.GetCell(36).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_dlsb = null;
                    //}
                    //if (row.GetCell(37) != null && row.GetCell(37).ToString() != "")
                    //{
                    //    model.ZlrzNum_dlbh = decimal.Parse(row.GetCell(37).ToString());
                    //}
                    //else
                    //{
                    //    model.ZlrzNum_dlbh = null;
                    //}
                    list.Add(model);
                }
            }
            return list;
        }
        public FruProsecutionModel ExcelToModel(string pathName, string fileSuffix)
        {

            IWorkbook workbook = null;
            ISheet sheet = null;
            FruProsecutionModel pageModel = new FruProsecutionModel();
            FileStream fs = new FileStream(pathName, FileMode.Open, FileAccess.Read);
            switch (fileSuffix)
            {
                case ".xls":
                    workbook = new HSSFWorkbook(fs);
                    break;
                case ".xlsx":
                    workbook = new XSSFWorkbook(fs);
                    break;
                default:
                    workbook = new HSSFWorkbook(fs);
                    break;
            }
            sheet = workbook.GetSheetAt(0);
            
            if (sheet != null)
            {
                HSSFRow datarow1 = (HSSFRow)sheet.GetRow(4);
                if (datarow1.GetCell(3) != null)
                {
                    if (datarow1.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.MarketNum = (int)(datarow1.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow1.GetCell(3).ToString()))
                        {
                            pageModel.MarketNum = int.Parse(datarow1.GetCell(3).ToString());
                        }

                    }
                }           
                   
                
                

                HSSFRow datarow2 = (HSSFRow)sheet.GetRow(5);
                if (datarow2.GetCell(3) != null)
                {
                    if (datarow2.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.CdxMarket = (int)(datarow2.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow2.GetCell(3).ToString()))
                        {
                            pageModel.CdxMarket = int.Parse(datarow2.GetCell(3).ToString());
                        }

                    }
                }
                   
                
                    

                HSSFRow datarow3 = (HSSFRow)sheet.GetRow(6);
                if (datarow3.GetCell(3) != null)
                {
                    if (datarow3.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZypfMarket = (int)(datarow3.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow3.GetCell(3).ToString()))
                        {
                            pageModel.ZypfMarket = int.Parse(datarow3.GetCell(3).ToString());
                        }

                    }
                }
                   
                
                    

                HSSFRow datarow4 = (HSSFRow)sheet.GetRow(7);
                if (datarow4.GetCell(3) !=null )
                {
                    if (datarow4.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.QyxzhpfMarket = (int)(datarow4.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow4.GetCell(3).ToString()))
                        {
                            pageModel.QyxzhpfMarket = int.Parse(datarow4.GetCell(3).ToString());
                        }

                    }
                }
                   
                
                   

                HSSFRow datarow5 = (HSSFRow)sheet.GetRow(8);
                if (datarow5.GetCell(3) != null)
                {
                    if (datarow5.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.FruCompanyNum = (int)(datarow5.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow5.GetCell(3).ToString()))
                        {
                            pageModel.FruCompanyNum = int.Parse(datarow5.GetCell(3).ToString());
                        }

                    }
                }
                   
                
                    

                HSSFRow datarow6 = (HSSFRow)sheet.GetRow(9);
                if (datarow6.GetCell(3) != null)
                {
                    if (datarow6.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZzNum_country = (int)(datarow6.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow6.GetCell(3).ToString()))
                        {
                            pageModel.ZzNum_country = int.Parse(datarow6.GetCell(3).ToString());
                        }

                    }
                }
                   
                
                    

                HSSFRow datarow7 = (HSSFRow)sheet.GetRow(10);
                if (datarow7.GetCell(3) != null)
                {
                    if (datarow7.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZzNum_pro = (int)(datarow7.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow7.GetCell(3).ToString()))
                        {
                            pageModel.ZzNum_pro = int.Parse(datarow7.GetCell(3).ToString());
                        }

                    }
                }
                    
                
                    

                HSSFRow datarow8 = (HSSFRow)sheet.GetRow(11);
                if (datarow8.GetCell(3) != null)
                {
                    if (datarow8.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZzNum_city = (int)(datarow8.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow8.GetCell(3).ToString()))
                        {
                            pageModel.ZzNum_city = int.Parse(datarow8.GetCell(3).ToString());
                        }

                    }
                }
                  
                
                    

                HSSFRow datarow9 = (HSSFRow)sheet.GetRow(12);
                if (datarow9.GetCell(3) != null)
                {
                    if (datarow9.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZzNum_county = (int)(datarow9.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow9.GetCell(3).ToString()))
                        {
                            pageModel.ZzNum_county = int.Parse(datarow9.GetCell(3).ToString());
                        }

                    }
                }
                   
                
                   

                HSSFRow datarow10 = (HSSFRow)sheet.GetRow(13);
                if (datarow10.GetCell(3) != null)
                {
                    if (datarow10.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZzNum_other = (int)(datarow10.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow10.GetCell(3).ToString()))
                        {
                            pageModel.ZzNum_other = int.Parse(datarow10.GetCell(3).ToString());
                        }

                    }
                }
               
                
                    

                HSSFRow datarow11 = (HSSFRow)sheet.GetRow(15);
                if (datarow11.GetCell(3) != null)
                {
                    if (datarow11.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.HzNum = (int)(datarow11.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow11.GetCell(3).ToString()))
                        {
                            pageModel.HzNum = int.Parse(datarow11.GetCell(3).ToString());
                        }

                    }
                }
               
               
                   

                HSSFRow datarow12 = (HSSFRow)sheet.GetRow(16);
                if (datarow12.GetCell(3) != null)
                {
                    if (datarow12.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.NhhzNum = (int)(datarow12.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow12.GetCell(3).ToString()))
                        {
                            pageModel.NhhzNum = int.Parse(datarow12.GetCell(3).ToString());
                        }

                    }
                }
               
                
                    

                HSSFRow datarow13 = (HSSFRow)sheet.GetRow(17);
                if (datarow13.GetCell(3) != null )
                {
                    if (datarow13.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.NmzyhzNum = decimal.Parse(datarow13.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow13.GetCell(3).ToString()))
                        {
                            pageModel.NmzyhzNum = decimal.Parse(datarow13.GetCell(3).ToString());
                        }

                    }
                }
               
                
                    

                HSSFRow datarow30 = (HSSFRow)sheet.GetRow(18);
                if (datarow30.GetCell(3) != null)
                {
                    if (datarow30.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.HzlzArea = decimal.Parse(datarow30.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow30.GetCell(3).ToString()))
                        {
                            pageModel.HzlzArea = decimal.Parse(datarow30.GetCell(3).ToString());
                        }

                    }
                }
                
                
                    

                HSSFRow datarow14 = (HSSFRow)sheet.GetRow(19);
                if (datarow14.GetCell(3) != null)
                {
                    if (datarow14.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.NmhzYincome = decimal.Parse(datarow14.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow14.GetCell(3).ToString()))
                        {
                            pageModel.NmhzYincome = decimal.Parse(datarow14.GetCell(3).ToString());
                        }

                    }
                }
                
                
                   

                HSSFRow datarow15 = (HSSFRow)sheet.GetRow(21);
                if (datarow15.GetCell(3) != null)
                {
                    if (datarow15.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.JtncNum = (int)(datarow15.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow15.GetCell(3).ToString()))
                        {
                            pageModel.JtncNum = int.Parse(datarow15.GetCell(3).ToString());
                        }

                    }
                }
                
               
                    

                HSSFRow datarow16 = (HSSFRow)sheet.GetRow(22);
                if (datarow16.GetCell(3) != null)
                {
                    if (datarow16.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.JtncnhNum = (int)(datarow16.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow16.GetCell(3).ToString()))
                        {
                            pageModel.JtncnhNum = int.Parse(datarow16.GetCell(3).ToString());
                        }

                    }
                }
               
                
                    

                HSSFRow datarow17 = (HSSFRow)sheet.GetRow(23);
                if (datarow17.GetCell(3) != null)
                {
                    if (datarow17.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.JtncjyArea = decimal.Parse(datarow17.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow17.GetCell(3).ToString()))
                        {
                            pageModel.JtncjyArea = decimal.Parse(datarow17.GetCell(3).ToString());
                        }

                    }
                }
               
                
                    

                HSSFRow datarow31 = (HSSFRow)sheet.GetRow(24);
                if (datarow31.GetCell(3) != null )
                {
                    if (datarow31.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.JtnclzArea = decimal.Parse(datarow31.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow31.GetCell(3).ToString()))
                        {
                            pageModel.JtnclzArea = decimal.Parse(datarow31.GetCell(3).ToString());
                        }

                    }
                }
               
               
                    

                HSSFRow datarow18 = (HSSFRow)sheet.GetRow(25);
                if (datarow18.GetCell(3) != null)
                {
                    if (datarow18.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.JtncYincome = decimal.Parse(datarow18.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow18.GetCell(3).ToString()))
                        {
                            pageModel.JtncYincome = decimal.Parse(datarow18.GetCell(3).ToString());
                        }

                    }
                }
               
               
                    

                HSSFRow datarow19 = (HSSFRow)sheet.GetRow(27);
                if (datarow19.GetCell(3) != null)
                {
                    if (datarow19.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_sfx = (int)(datarow19.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow19.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_sfx = int.Parse(datarow19.GetCell(3).ToString());
                        }

                    }
                }
               
               
                   

                HSSFRow datarow20 = (HSSFRow)sheet.GetRow(28);
                if (datarow20.GetCell(3) != null)
                {
                    if (datarow20.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_sfq = (int)(datarow20.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow20.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_sfq = int.Parse(datarow20.GetCell(3).ToString());
                        }

                    }
                }
                
               

                HSSFRow datarow21 = (HSSFRow)sheet.GetRow(29);
                if (datarow21.GetCell(3) != null)
                {
                    if (datarow21.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZgcmsbNum = (int)(datarow21.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow21.GetCell(3).ToString()))
                        {
                            pageModel.ZgcmsbNum = int.Parse(datarow21.GetCell(3).ToString());
                        }

                    }
                }
                
                
                    

                HSSFRow datarow22 = (HSSFRow)sheet.GetRow(30);
                if (datarow22.GetCell(3) != null)
                {
                    if (datarow22.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZgmpcpNum = (int)(datarow22.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow22.GetCell(3).ToString()))
                        {
                            pageModel.ZgmpcpNum = int.Parse(datarow22.GetCell(3).ToString());
                        }

                    }
                }
                
               
                    

                HSSFRow datarow23 = (HSSFRow)sheet.GetRow(31);
                if (datarow23.GetCell(3) != null)
                {
                    if (datarow23.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.YnszmsbNum = (int)(datarow23.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow23.GetCell(3).ToString()))
                        {
                            pageModel.YnszmsbNum = int.Parse(datarow23.GetCell(3).ToString());
                        }

                    }
                }
               
                
                    

                HSSFRow datarow24 = (HSSFRow)sheet.GetRow(32);
                if (datarow24.GetCell(3) != null)
                {
                    if (datarow24.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_wghNum = (int)(datarow24.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow24.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_wghNum = int.Parse(datarow24.GetCell(3).ToString());
                        }

                    }
                }
               
               
                    

                HSSFRow datarow25 = (HSSFRow)sheet.GetRow(33);
                 if (datarow25.GetCell(3) != null)
                {
                    if (datarow25.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_wghmj = decimal.Parse(datarow25.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow25.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_wghmj = decimal.Parse(datarow25.GetCell(3).ToString());
                        }

                    }
                }
                
                
                    

                HSSFRow datarow26 = (HSSFRow)sheet.GetRow(34);
                if (datarow26.GetCell(3) != null)
                {
                    if (datarow26.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_bluecp = (int)(datarow26.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow26.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_bluecp = int.Parse(datarow26.GetCell(3).ToString());
                        }

                    }
                }
                
               
                    

                HSSFRow datarow27 = (HSSFRow)sheet.GetRow(35);
                if (datarow27.GetCell(3) != null )
                {
                    if (datarow27.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_bluecpmj = decimal.Parse(datarow27.GetCell(3).NumericCellValue.ToString());
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow27.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_bluecpmj = decimal.Parse(datarow27.GetCell(3).ToString());
                        }

                    }
                }
               
               
                    

                HSSFRow datarow28 = (HSSFRow)sheet.GetRow(36);
                if (datarow28.GetCell(3) != null)
                {
                    if (datarow28.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_dlsb = (int)(datarow28.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow28.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_dlsb = int.Parse(datarow28.GetCell(3).ToString());
                        }

                    }
                }
                
               
                    

                HSSFRow datarow29 = (HSSFRow)sheet.GetRow(37);
                if (datarow29.GetCell(3) != null)
                {
                    if (datarow29.GetCell(3).CellType == CellType.Formula)
                    {
                        pageModel.ZlrzNum_dlbh = (int)(datarow29.GetCell(3).NumericCellValue);
                    }
                    else
                    {
                        if (DataCheck.isNumber(datarow29.GetCell(3).ToString()))
                        {
                            pageModel.ZlrzNum_dlbh = int.Parse(datarow29.GetCell(3).ToString());
                        }

                    }
                }
               
               
                    


            }
            return pageModel;
        }
        /// <summary>
        /// 初始化报表内容
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public ResResult<int> AddInfo(FruProsecutionModel model)
        {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"INSERT INTO dbo.T_FruProsecution";
            strSql += "(";
            strSql += "Id,";
            strSql += "ReportId,";
            strSql += "marketNum,";
            strSql += "cdxMarket,";
            strSql += "zypfMarket,";
            strSql += "qyxzhpfMarket,";
            strSql += "FruCompanyNum,";
            strSql += "zzNum_country,";
            strSql += "zzNum_pro,";
            strSql += "zzNum_city,";
            strSql += "zzNum_county,";
            strSql += "zzNum_other,";
            strSql += "zzNum_singel,";
            strSql += "zzNum_yye1,";
            strSql += "zzNum_yye2,";
            strSql += "zzNum_yye3,";
            strSql += "zzNum_yye4,";
            strSql += "zzNum_yye5,";
            strSql += "zzNum_yye6,";
            strSql += "SgjgNum,";
            strSql += "SgyxNum,";
            strSql += "SgwmNum,";
            strSql += "nmzyhzNum,";
            strSql += "sgzzNhNum,";
            strSql += "ZZDHNum,";
            strSql += "ZZDHOne,";
            strSql += "ZZDHTwo,";
            strSql += "ZZDHThree,";
            strSql += "ymjdNum,";
            strSql += "ymNum,";
            strSql += "DzswNum,";
            strSql += "HzNum,";
            strSql += "zyhzNum,";
            strSql += "nhhzNum,";
            strSql += "hzlzArea,";
            strSql += "nmhzYincome,";
            strSql += "jtncNum,";
            strSql += "jtncnhNum,";
            strSql += "jtncjyArea,";
            strSql += "jtnclzArea,";
            strSql += "jtncYincome,";
            strSql += "zlrzNum_sfx,";
            strSql += "zlrzNum_sfq,";
            strSql += "zgcmsbNum,";
            strSql += "zgmpcpNum,";
            strSql += "ynszmsbNum,";
            strSql += "zlrzNum_sbs,";
            strSql += "zlrzNum_bamj,";
            strSql += "zlrzNum_rzmj,";
            strSql += "zlrzNum_rzsl,";
            strSql += "zlrzNum_wghmj,";
            strSql += "zlrzNum_bluecp,";
            strSql += "zlrzNum_bluecpmj,";
            strSql += "zlrzNum_dlsb,";
            strSql += "zlrzNum_dlbh,";
            strSql += "zlrzNum_wghNum,";
            strSql += "AddUser,";
            strSql += "AddTime,";
            strSql += "UpdateUser,";
            strSql += "UpdateTime)";
            strSql += " values(";
            strSql += "@Id,";
            strSql += "@ReportId,";
            strSql += "@marketNum,";
            strSql += "@cdxMarket,";
            strSql += "@zypfMarket,";
            strSql += "@qyxzhpfMarket,";
            strSql += "@FruCompanyNum,";
            strSql += "@zzNum_country,";
            strSql += "@zzNum_pro,";
            strSql += "@zzNum_city,";
            strSql += "@zzNum_county,";
            strSql += "@zzNum_other,";
            strSql += "@zzNum_singel,";
            strSql += "@zzNum_yye1,";
            strSql += "@zzNum_yye2,";
            strSql += "@zzNum_yye3,";
            strSql += "@zzNum_yye4,";
            strSql += "@zzNum_yye5,";
            strSql += "@zzNum_yye6,";
            strSql += "@SgjgNum,";
            strSql += "@SgyxNum,";
            strSql += "@SgwmNum,";
            strSql += "@nmzyhzNum,";
            strSql += "@sgzzNhNum,";
            strSql += "@ZZDHNum,";
            strSql += "@ZZDHOne,";
            strSql += "@ZZDHTwo,";
            strSql += "@ZZDHThree,";
            strSql += "@ymjdNum,";
            strSql += "@ymNum,";
            strSql += "@DzswNum,";
            strSql += "@HzNum,";
            strSql += "@zyhzNum,";
            strSql += "@nhhzNum,";
            strSql += "@hzlzArea,";
            strSql += "@nmhzYincome,";
            strSql += "@jtncNum,";
            strSql += "@jtncnhNum,";
            strSql += "@jtncjyArea,";
            strSql += "@jtnclzArea,";
            strSql += "@jtncYincome,";
            strSql += "@zlrzNum_sfx,";
            strSql += "@zlrzNum_sfq,";
            strSql += "@zgcmsbNum,";
            strSql += "@zgmpcpNum,";
            strSql += "@ynszmsbNum,";
            strSql += "@zlrzNum_sbs,";
            strSql += "@zlrzNum_bamj,";
            strSql += "@zlrzNum_rzmj,";
            strSql += "@zlrzNum_rzsl,";
            strSql += "@zlrzNum_wghmj,";
            strSql += "@zlrzNum_bluecp,";
            strSql += "@zlrzNum_bluecpmj,";
            strSql += "@zlrzNum_dlsb,";
            strSql += "@zlrzNum_dlbh,";
            strSql += "@zlrzNum_wghNum,";
            strSql += "@AddUser,";
            strSql += "@AddTime,";
            strSql += "@UpdateUser,";
            strSql += "@UpdateTime)";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    model.Id = CustomFun.GetGuid();
                    int result = dbCon.Execute(strSql, model);
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "添加成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "添加失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("新增表5生产经营实体表T_FruProsecution对象信息失败", ex);
            }
            return obj;
        }
        public ResResult<int> UpdateInfo(FruProsecutionModel model)
        {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"UPDATE dbo.T_FruProsecution set ";
            strSql += "ReportId = @ReportId,";
            strSql += "marketNum = @MarketNum,";
            strSql += "cdxMarket = @CdxMarket ,";
            strSql += "zypfMarket = @ZypfMarket ,";
            strSql += "qyxzhpfMarket = @QyxzhpfMarket ,";
            strSql += "FruCompanyNum = @FruCompanyNum,";
            strSql += "zzNum_country = @zzNum_country,";
            strSql += "zzNum_pro = @ZzNum_pro,";
            strSql += "zzNum_city = @ZzNum_city,";
            strSql += "zzNum_county = @zzNum_county,";
            strSql += "zzNum_other = @zzNum_other,";
            strSql += "zzNum_singel = @ZzNum_singel,";
            strSql += "zzNum_yye1 = @ZzNum_yye1,";
            strSql += "zzNum_yye2 = @ZzNum_yye2,";
            strSql += "zzNum_yye3 = @ZzNum_yye3,";
            strSql += "zzNum_yye4 = @ZzNum_yye4,";
            strSql += "zzNum_yye5 = @ZzNum_yye5,";
            strSql += "zzNum_yye6 = @ZzNum_yye6,";
            strSql += "SgjgNum = @SgjgNum,";
            strSql += "SgyxNum = @SgyxNum,";
            strSql += "SgwmNum = @SgwmNum,";
            strSql += "nmzyhzNum = @NmzyhzNum,";
            strSql += "hzlzArea = @HzlzArea,";
            strSql += "nmhzYincome = @NmhzYincome ,";
            strSql += "jtncNum = @JtncNum ,";
            strSql += "jtncnhNum = @JtncnhNum ,";
            strSql += "jtncjyArea = @JtncjyArea ,";
            strSql += "jtnclzArea = @JtnclzArea ,";
            strSql += "JtncYincome = @JtncYincome ,";
            strSql += "sgzzNhNum = @SgzzNhNum,";
            strSql += "ZZDHNum = @ZZDHNum,";
            strSql += "ZZDHOne = @ZZDHOne,";
            strSql += "ZZDHTwo = @ZZDHTwo,";
            strSql += "ZZDHThree = @ZZDHThree,";
            strSql += "ymjdNum = @YmjdNum,";
            strSql += "ymNum = @YmNum,";
            strSql += "DzswNum = @DzswNum,";
            strSql += "HzNum = @HzNum,";
            strSql += "zyhzNum = @ZyhzNum,";
            strSql += "nhhzNum = @NhhzNum,";
            strSql += "zlrzNum_sfx = @ZlrzNum_sfx,";
            strSql += "zlrzNum_sfq = @ZlrzNum_sfq,";
            strSql += "ZgcmsbNum = @ZgcmsbNum ,";
            strSql += "ZgmpcpNum = @ZgmpcpNum ,";
            strSql += "YnszmsbNum = @YnszmsbNum ,";
            strSql += "zlrzNum_sbs = @ZlrzNum_sbs,";
            strSql += "zlrzNum_bamj = @ZlrzNum_bamj,";
            strSql += "zlrzNum_rzmj = @ZlrzNum_rzmj,";
            strSql += "zlrzNum_rzsl = @ZlrzNum_rzsl,";
            strSql += "zlrzNum_wghmj = @ZlrzNum_wghmj,";
            strSql += "zlrzNum_bluecp = @ZlrzNum_bluecp,";
            strSql += "zlrzNum_bluecpmj = @ZlrzNum_bluecpmj,";
            strSql += "zlrzNum_dlsb = @ZlrzNum_dlsb,";
            strSql += "zlrzNum_dlbh = @ZlrzNum_dlbh,";
            strSql += "zlrzNum_wghNum = @ZlrzNum_wghNum,";
            strSql += "AddUser = @AddUser,";
            strSql += "AddTime = @AddTime,";
            strSql += "UpdateUser = @UpdateUser,";
            strSql += "UpdateTime = @UpdateTime";
            strSql += " where ReportId = @ReportId";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    int result = dbCon.Execute(strSql, model);
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "更新成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "更新失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("更新表5生产经营实体表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 获取报表内容
        /// </summary>
        /// <param name="reportId"></param>
        /// <param name="edittype">0的时候返回视图列表，不为0的时候返回数据库列表</param>
        /// <returns></returns>
        public List<FruProsecutionEntity> GetTabContent(string reportId, int edittype)
        {
            List<FruProsecutionEntity> obj = new List<FruProsecutionEntity>();
            string strSql = "";
            if (edittype == 0)
            {
                strSql = @"select * from dbo.V_FruProsecution order by SortCode asc,ItemCode asc";
            }
            else
            {
                strSql = @"select * from dbo.T_FruProsecution where ReportId='" + reportId + "' order by SortCode asc,ItemCode asc";
            }
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj = dbCon.Query<FruProsecutionEntity>(strSql).ToList();
                    if (edittype == 0)
                    {
                        foreach (var item in obj)
                        {
                            item.ReportId = reportId;
                            item.Id = CustomFun.GetGuid();
                        }
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("更新表3生产情况调查表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
        public override ResResult<FruProsecutionEntity> GetModel(string ReportId)
        {
            ResResult<FruProsecutionEntity> obj = new ResResult<FruProsecutionEntity>();
            FruProsecutionEntity model = new FruProsecutionEntity();
            if (CheckRepCount(ReportId))
            {
                model.ReportId = ReportId;
                if (AddInfo(model).status > 0)
                {
                    obj.model = model;
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                }
            }
            else
            {
                string strSql = @"select * from dbo.T_FruProsecution where ReportId = @ReportId";
                try
                {
                    using (var dbCon = ConnectFactory.GetOpenConnection())
                    {
                        obj.model = dbCon.Query<FruProsecutionEntity>(strSql, new { ReportId = ReportId }).FirstOrDefault();
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "获取成功！";
                        dbCon.Dispose();//数据库连接释放
                    }
                }
                catch (Exception ex)
                {
                    obj.status = DefaultKey.ErrorResult;
                    obj.message = ex.ToString().Trim();
                    LogHelper.ErrorLog("获取水果经营实体情况调查T_FruProsecution对象信息失败", ex);
                }
            }
            return obj;
        }

        public ResResult<List<ProsecutionStatisModel>> getStatisListData(string AreaCode, string FillInYear)
        {
            ResResult<List<ProsecutionStatisModel>> obj = new ResResult<List<ProsecutionStatisModel>>();
            List<ProsecutionStatisModel> list = new List<ProsecutionStatisModel>();
            AreaServices areaServices = new AreaServices();
            if (AreaCode.Equals("530000000000"))
            {
                var citylist = areaServices.GetPrefectureList();
                ProsecutionStatisModel totalModel = new ProsecutionStatisModel();
                totalModel.AreaCode = AreaCode;
                totalModel.AreaName = "合计";
                totalModel.tag = 2;
                totalModel.MarketNum = 0;
                totalModel.CdxMarket = 0;
                totalModel.ZypfMarket = 0;
                totalModel.QyxzhpfMarket = 0;
                totalModel.FruCompanyNum = 0;
                totalModel.ZzNum_country = 0;
                totalModel.ZzNum_pro = 0;
                totalModel.ZzNum_city = 0;
                totalModel.ZzNum_county = 0;
                totalModel.ZzNum_other = 0;
                totalModel.HzNum = 0;
                totalModel.NhhzNum = 0;
                totalModel.NmzyhzNum = 0;
                totalModel.HzlzArea = 0;
                totalModel.NmhzYincome = 0;
                totalModel.JtncNum = 0;
                totalModel.JtncnhNum = 0;
                totalModel.JtncjyArea = 0;
                totalModel.JtnclzArea = 0;
                totalModel.JtncYincome = 0;
                totalModel.ZlrzNum_sfx = 0;
                totalModel.ZlrzNum_sfq = 0;
                totalModel.ZgcmsbNum = 0;
                totalModel.ZgmpcpNum = 0;
                totalModel.YnszmsbNum = 0;
                totalModel.ZlrzNum_wghNum = 0;
                totalModel.ZlrzNum_wghmj = 0;
                totalModel.ZlrzNum_bluecp = 0;
                totalModel.ZlrzNum_bluecpmj = 0;
                totalModel.ZlrzNum_dlsb = 0;
                totalModel.ZlrzNum_dlbh = 0;
                foreach (string code in citylist)
                {
                    ProsecutionStatisModel model = getProvinStatisList(code, FillInYear);
                    if (model != null)
                    {
                        //int len = templist.Count;
                        //templist[len - 1].AreaName = areaServices.GetByCodeModel(code).model.Name;
                       // templist[len - 1].tag = 1;   
                       model.AreaName = areaServices.GetByCodeModel(code).model.FullName;
                        totalModel.MarketNum += model.MarketNum;
                        totalModel.CdxMarket += model.CdxMarket;
                        totalModel.ZypfMarket += model.ZypfMarket;
                        totalModel.QyxzhpfMarket += model.QyxzhpfMarket;
                        totalModel.FruCompanyNum += model.FruCompanyNum;
                        totalModel.ZzNum_country += model.ZzNum_country;
                        totalModel.ZzNum_pro += model.ZzNum_pro;
                        totalModel.ZzNum_city += model.ZzNum_city;
                        totalModel.ZzNum_county += model.ZzNum_county;
                        totalModel.ZzNum_other += model.ZzNum_other;
                        totalModel.HzNum += model.HzNum;
                        totalModel.NhhzNum += model.NhhzNum;
                        totalModel.NmzyhzNum += model.NmzyhzNum;
                        totalModel.HzlzArea += model.HzlzArea;
                        totalModel.NmhzYincome += model.NmhzYincome;
                        totalModel.JtncNum += model.JtncNum;
                        totalModel.JtncnhNum += model.JtncnhNum;
                        totalModel.JtncjyArea += model.JtncjyArea;
                        totalModel.JtnclzArea += model.JtnclzArea;
                        totalModel.JtncYincome += model.JtncYincome;
                        totalModel.ZlrzNum_sfx += model.ZlrzNum_sfx;
                        totalModel.ZlrzNum_sfq += model.ZlrzNum_sfq;
                        totalModel.ZgcmsbNum += model.ZgcmsbNum;
                        totalModel.ZgmpcpNum += model.ZgmpcpNum;
                        totalModel.YnszmsbNum += model.YnszmsbNum;
                        totalModel.ZlrzNum_wghNum += model.ZlrzNum_wghNum;
                        totalModel.ZlrzNum_wghmj += model.ZlrzNum_wghmj;
                        totalModel.ZlrzNum_bluecp += model.ZlrzNum_bluecp;
                        totalModel.ZlrzNum_bluecpmj += model.ZlrzNum_bluecpmj;
                        totalModel.ZlrzNum_dlsb += model.ZlrzNum_dlsb;
                        totalModel.ZlrzNum_dlbh += model.ZlrzNum_dlbh;
                        list.Add(model);
                    }                    
                }
                list.Add(totalModel);
            }
            else
            {
                if (AreaCode.Substring(4, 8).Equals("00000000"))
                {
                    list = getStatisList(AreaCode, FillInYear);
                    int len = list.Count;
                   // list[len - 1].tag = 1;
                }
                else
                {
                    list = getCountyStatisList(AreaCode, FillInYear);
                }
            }
            obj.model = list;
            obj.status = DefaultKey.SuccessResult;
            obj.message = "获取成功";
            return obj;
        }

        public ProsecutionStatisModel getProvinStatisList(string AreaCode, string FillInYear)
        {
            ProsecutionStatisModel model = new ProsecutionStatisModel();
            string strSql = "select  ";           
            strSql += "isnull(sum(t3.marketNum),0.00) MarketNum ,";
            strSql += "isnull(sum(t3.cdxMarket),0.00) CdxMarket ,";
            strSql += "isnull(sum(t3.zypfMarket),0.00) ZypfMarket ,";
            strSql += "isnull(sum(t3.qyxzhpfMarket),0.00) QyxzhpfMarket ,";
            strSql += "isnull(sum(t3.FruCompanyNum),0.00) FruCompanyNum,";
            strSql += "isnull(sum(t3.zzNum_country),0.00) ZzNum_country,";
            strSql += "isnull(sum(t3.zzNum_pro),0.00) ZzNum_pro,";
            strSql += "isnull(sum(t3.zzNum_city),0.00) ZzNum_city ,";
            strSql += "isnull(sum(t3.zzNum_county),0.00) ZzNum_county ,";
            strSql += "isnull(sum(t3.zzNum_other),0.00) ZzNum_other ,";
            strSql += "isnull(sum(t3.HzNum),0.00) HzNum ,";
            strSql += "isnull(sum(t3.nhhzNum),0.00) NhhzNum ,";
            strSql += "isnull(sum(t3.nmzyhzNum),0.00) NmzyhzNum ,";
            strSql += "isnull(sum(t3.hzlzArea),0.00) HzlzArea ,";
            strSql += "isnull(sum(t3.nmhzYincome),0.00) NmhzYincome ,";
            strSql += "isnull(sum(t3.jtncNum),0.00) JtncNum ,";
            strSql += "isnull(sum(t3.jtncnhNum),0.00) JtncnhNum ,";
            strSql += "isnull(sum(t3.jtncjyArea),0.00) JtncjyArea ,";
            strSql += "isnull(sum(t3.jtnclzArea),0.00) JtnclzArea ,";
            strSql += "isnull(sum(t3.jtncYincome),0.00) JtncYincome ,";
            strSql += "isnull(sum(t3.zlrzNum_sfx),0.00) ZlrzNum_sfx ,";
            strSql += "isnull(sum(t3.zlrzNum_sfq),0.00) ZlrzNum_sfq ,";
            strSql += "isnull(sum(t3.zgcmsbNum),0.00) ZgcmsbNum ,";
            strSql += "isnull(sum(t3.zgmpcpNum),0.00) ZgmpcpNum ,";
            strSql += "isnull(sum(t3.ynszmsbNum),0.00) YnszmsbNum,";
            strSql += "isnull(sum(t3.zlrzNum_wghNum),0.00) ZlrzNum_wghNum ,";
            strSql += "isnull(sum(t3.zlrzNum_wghmj),0.00) ZlrzNum_wghmj ,";
            strSql += "isnull(sum(t3.zlrzNum_bluecp),0.00) ZlrzNum_bluecp ,";
            strSql += "isnull(sum(t3.zlrzNum_bluecpmj),0.00) ZlrzNum_bluecpmj ,";
            strSql += "isnull(sum(t3.zlrzNum_dlsb),0.00) ZlrzNum_dlsb ,";
            strSql += "isnull(sum(t3.ZlrzNum_dlbh),0.00) ZlrzNum_dlbh ";
            strSql += " from T_Area t1 left join";
            strSql += " T_Report t2 on t2.AreaCode = t1.Code ";
            strSql += "left join  T_FruProsecution t3 on t2.Id = t3.ReportId where t2.ReportCode = 'FruProsecution' and t1.ParentCode = @AreaCode and t2.FillInYear = @FillInYear ";
            strSql += "  and t2.Status = '4' ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    model = dbCon.Query<ProsecutionStatisModel>(strSql, new { AreaCode = AreaCode, FillInYear = FillInYear }).FirstOrDefault();
                    dbCon.Dispose();//数据库连接释放
                }
            }
            catch (Exception ex)
            {
                return null;
                LogHelper.ErrorLog("获取水果经营实体情况调查统计列表信息失败", ex);
            }
            return model;
        }
        public List<ProsecutionStatisModel> getStatisList(string AreaCode,string FillInYear)
        {
            List<ProsecutionStatisModel> list = new List<ProsecutionStatisModel>();
            string strSql = "select t.Name AreaName,tt.* from (";
            strSql += "select case when grouping(t1.Code)=1 then '" + AreaCode + "' else Code end AreaCode,";
            strSql += "isnull(sum(t3.marketNum),0.00) MarketNum ,";
            strSql += "isnull(sum(t3.cdxMarket),0.00) CdxMarket ,";
            strSql += "isnull(sum(t3.zypfMarket),0.00) ZypfMarket ,";
            strSql += "isnull(sum(t3.qyxzhpfMarket),0.00) QyxzhpfMarket ,";
            strSql += "isnull(sum(t3.FruCompanyNum),0.00) FruCompanyNum,";
            strSql += "isnull(sum(t3.zzNum_country),0.00) ZzNum_country,";
            strSql += "isnull(sum(t3.zzNum_pro),0.00) ZzNum_pro,";
            strSql += "isnull(sum(t3.zzNum_city),0.00) ZzNum_city ,";
            strSql += "isnull(sum(t3.zzNum_county),0.00) ZzNum_county ,";
            strSql += "isnull(sum(t3.zzNum_other),0.00) ZzNum_other ,";
            strSql += "isnull(sum(t3.HzNum),0.00) HzNum ,";
            strSql += "isnull(sum(t3.nhhzNum),0.00) NhhzNum ,";
            strSql += "isnull(sum(t3.nmzyhzNum),0.00) NmzyhzNum ,";
            strSql += "isnull(sum(t3.hzlzArea),0.00) HzlzArea ,";
            strSql += "isnull(sum(t3.nmhzYincome),0.00) NmhzYincome ,";
            strSql += "isnull(sum(t3.jtncNum),0.00) JtncNum ,";
            strSql += "isnull(sum(t3.jtncnhNum),0.00) JtncnhNum ,";
            strSql += "isnull(sum(t3.jtncjyArea),0.00) JtncjyArea ,";
            strSql += "isnull(sum(t3.jtnclzArea),0.00) JtnclzArea ,";
            strSql += "isnull(sum(t3.jtncYincome),0.00) JtncYincome ,";
            strSql += "isnull(sum(t3.zlrzNum_sfx),0.00) ZlrzNum_sfx ,";
            strSql += "isnull(sum(t3.zlrzNum_sfq),0.00) ZlrzNum_sfq ,";
            strSql += "isnull(sum(t3.zgcmsbNum),0.00) ZgcmsbNum ,";
            strSql += "isnull(sum(t3.zgmpcpNum),0.00) ZgmpcpNum ,";
            strSql += "isnull(sum(t3.ynszmsbNum),0.00) YnszmsbNum,";
            strSql += "isnull(sum(t3.zlrzNum_wghNum),0.00) ZlrzNum_wghNum ,";
            strSql += "isnull(sum(t3.zlrzNum_wghmj),0.00) ZlrzNum_wghmj ,";
            strSql += "isnull(sum(t3.zlrzNum_bluecp),0.00) ZlrzNum_bluecp ,";
            strSql += "isnull(sum(t3.zlrzNum_bluecpmj),0.00) ZlrzNum_bluecpmj ,";
            strSql += "isnull(sum(t3.zlrzNum_dlsb),0.00) ZlrzNum_dlsb ,";
            strSql += "isnull(sum(t3.ZlrzNum_dlbh),0.00) ZlrzNum_dlbh ";
            strSql += " from T_Area t1 left join";
            strSql += " T_Report t2 on t2.AreaCode = t1.Code ";
            strSql += "left join  T_FruProsecution t3 on t2.Id = t3.ReportId where t2.ReportCode = 'FruProsecution' and t1.ParentCode = @AreaCode and t2.FillInYear = @FillInYear ";
            strSql += "  and t2.Status = '4' ";
            strSql += "group by rollup(t1.Code)";
            strSql += " )tt inner join  T_Area t on t.Code = tt.AreaCode order by t.Code desc";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    list = dbCon.Query<ProsecutionStatisModel>(strSql, new { AreaCode = AreaCode, FillInYear = FillInYear }).ToList();
                    dbCon.Dispose();//数据库连接释放
                }
            }
            catch (Exception ex)
            {
                return null;
                LogHelper.ErrorLog("获取水果经营实体情况调查统计列表信息失败", ex);
            }
            return list;
        }

        public List<ProsecutionStatisModel> getCountyStatisList(string AreaCode, string FillInYear)
        {
            List<ProsecutionStatisModel> list = new List<ProsecutionStatisModel>();
            string strSql = "select t1.Name AreaName,";
            strSql += "isnull(t3.marketNum,0.00) MarketNum ,";
            strSql += "isnull(t3.cdxMarket,0.00) CdxMarket ,";
            strSql += "isnull(t3.zypfMarket,0.00) ZypfMarket ,";
            strSql += "isnull(t3.qyxzhpfMarket,0.00) QyxzhpfMarket ,";
            strSql += "isnull(t3.FruCompanyNum,0.00) FruCompanyNum,";
            strSql += "isnull(t3.zzNum_country,0.00) ZzNum_country,";
            strSql += "isnull(t3.zzNum_pro,0.00) ZzNum_pro,";
            strSql += "isnull(t3.zzNum_city,0.00) ZzNum_city ,";
            strSql += "isnull(t3.zzNum_county,0.00) ZzNum_county ,";
            strSql += "isnull(t3.zzNum_other,0.00) ZzNum_other ,";
            strSql += "isnull(t3.HzNum,0.00) HzNum ,";
            strSql += "isnull(t3.nhhzNum,0.00) NhhzNum ,";
            strSql += "isnull(t3.nmzyhzNum,0.00) NmzyhzNum ,";
            strSql += "isnull(t3.hzlzArea,0.00) HzlzArea ,";
            strSql += "isnull(t3.nmhzYincome,0.00) NmhzYincome ,";
            strSql += "isnull(t3.jtncNum,0.00) JtncNum ,";
            strSql += "isnull(t3.jtncnhNum,0.00) JtncnhNum ,";
            strSql += "isnull(t3.jtncjyArea,0.00) JtncjyArea ,";
            strSql += "isnull(t3.jtnclzArea,0.00) JtnclzArea ,";
            strSql += "isnull(t3.jtncYincome,0.00) JtncYincome ,";
            strSql += "isnull(t3.zlrzNum_sfx,0.00) ZlrzNum_sfx ,";
            strSql += "isnull(t3.zlrzNum_sfq,0.00) ZlrzNum_sfq ,";
            strSql += "isnull(t3.zgcmsbNum,0.00) ZgcmsbNum ,";
            strSql += "isnull(t3.zgmpcpNum,0.00) ZgmpcpNum ,";
            strSql += "isnull(t3.ynszmsbNum,0.00) YnszmsbNum,";
            strSql += "isnull(t3.zlrzNum_wghNum,0.00) ZlrzNum_wghNum ,";
            strSql += "isnull(t3.zlrzNum_wghmj,0.00) ZlrzNum_wghmj ,";
            strSql += "isnull(t3.zlrzNum_bluecp,0.00) ZlrzNum_bluecp ,";
            strSql += "isnull(t3.zlrzNum_bluecpmj,0.00) ZlrzNum_bluecpmj ,";
            strSql += "isnull(t3.zlrzNum_dlsb,0.00) ZlrzNum_dlsb ,";
            strSql += "isnull(t3.ZlrzNum_dlbh,0.00) ZlrzNum_dlbh";
            strSql += " from T_Area t1 left join ";
            strSql += " T_Report t2 on t2.AreaCode = t1.Code ";
            strSql += " left join  T_FruProsecution t3 on t2.Id = t3.ReportId where t2.ReportCode = 'FruProsecution' and t1.Code = @AreaCode and t2.FillInYear = @FillInYear ";
            strSql += "  and t2.Status = '4' ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    list = dbCon.Query<ProsecutionStatisModel>(strSql, new { AreaCode = AreaCode, FillInYear = FillInYear }).ToList();
                    dbCon.Dispose();//数据库连接释放
                }
            }
            catch (Exception ex)
            {
                return null;
                LogHelper.ErrorLog("获取水果经营实体情况调查统计列表信息失败", ex);
            }
            return list;
        }
    }
}